/*************************************************************************
> File Name: 02_test.cpp
> Author: hzy
> Created Time: 2023-08-14 11:33:23
> Description:对象构造和析构的调用顺序
************************************************************************/
#include <iostream>

using namespace std;

class Base1
{
private:
    int val;

public:
    Base1(int myval)
    {
        val = myval;
        cout << "Base1()" << endl;
    }
    ~Base1()
    {
        cout << "~Base1()" << endl;
    }
};

class Base2
{
private:
    int num;

public:
    Base2(int mynum)
    {
        num = mynum;
        cout << "Base2()" << endl;
    }
    ~Base2()
    {
        cout << "~Base2()" << endl;
    }
};
class Son1 : public Base1
{
public:
    Base2 obj2;     //类对象作为类的成员变量

public:
    Son1(int mynum, int myval) : obj2(mynum), Base1(myval)
    {
        cout << "Son1()" << endl;
    }
    ~Son1()
    {
        cout << "~Son1()" << endl;
    }
};

int main()
{
    Son1 son1(1, 9);

    //cout << "son1.Base2.val = " << son1.obj2.num << endl;
    // cout << "son1.num = " << son1.val << endl;

    return 0;
}